<template>
	<view class="">
		<view class="tab"><lrTabs :tabs="tabs" @change="change"></lrTabs></view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view v-if="activityList.length > 0" v-for="(item, index) in activityList" :key="item.orderNo">
				<activity-order-list :orderObj="item"></activity-order-list>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import lrTabs from '@/components/activity/lr-tabs.vue'
	import activityOrderList from '@/components/activity/activity-orderList.vue'
	import {myOrderList,myOrderCount} from '@/api/marketing-api.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			lrTabs,
			activityOrderList
		},
		data() {
			return {
				activityStatus: 1,
				tabs: [
					{
						status:1,
						code : 0,
						value : '可使用'
					},
					{
						status:2,
						code : 0,
						value : '已使用'
					},
					{
						status:3,
						code : 0,
						value : '已过期'
					},
					{
						status:5,
						code : 0,
						value : '已退款'
					}
				],
				activityList: []
			}
		},
		methods: {
			upCallback(page) {
			  myOrderList({
					pageNo: page.num,
					activityStatus: this.activityStatus
				}).then(res => {
					this.mescroll.endSuccess(res.data.length);
					//设置列表数据
					if (page.num == 1) this.activityList = []; //如果是第一页需手动制空列表
					this.activityList = this.activityList.concat(res.data); //追加新数据
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			myOrderCount() {
			  myOrderCount().then(res => {
					let data = res.data[0];
					this.tabs[0].code = data.noUse
					this.tabs[1].code = data.alreadyUse
					this.tabs[2].code = data.alreadyOverdue
					this.tabs[3].code = data.alreadyRefund
				})
			},
			change(index) {
				let item = this.tabs[index];
				this.activityStatus =  item.status;
				this.mescroll.triggerDownScroll();
			}
			
		},
		onLoad() {
			this.myOrderCount();
		},
	
	}
</script>

<style lang="scss" scoped>
	.tab {
		position: sticky;
		top: 0;
		background-color: #F5F5F5;
		z-index: 2;
	}
</style>
